package com.pactera.asmp.server.common.bug.impl;

import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.pactera.asmp.server.common.bug.IBugHandler;
import com.pactera.asmp.server.utils.ApplicationContextUtil;
import com.pactera.asmp.server.utils.HttpService;

public abstract class AbstractBugHandler implements IBugHandler {

    private static final Logger logger = LoggerFactory.getLogger(AbstractBugHandler.class);

    protected static HttpService httpService;

    public static IBugHandler getBugHandler(String platform) {
        httpService = ApplicationContextUtil.getBean(HttpService.class);
        httpService.setHttpClient(null);
        IBugHandler handler = null;
        try {
            switch (platform) {
            case "TAPD":
                handler = (IBugHandler) ApplicationContextUtil.getBean(TapdHandlerImpl.class);
                break;
            case "ZENTAO":
                // 禅道需要登录时初始化赋值
                handler = (IBugHandler) ApplicationContextUtil.getBean(ZentaoHandlerImpl.class);
                break;
            case "JIRA":
                // jira 统一初始化赋值
                httpService.setHttpClient(HttpClients.createDefault());
                handler = (IBugHandler) ApplicationContextUtil.getBean(JiraBugHandlerImpl.class);
                break;
            }
        } catch (Exception e) {
            logger.error("AbstractBugHandler.getBugHandler() error: ", e);
        }
        return handler;
    }

}
